const fs = require("fs")
const path = require('path')
const moment = require("moment")
let file = path.resolve(__dirname, './Error.txt')

/**
 * 将异常写入本地文件
 * @param {*} str 异常文本
 */
function Writetext (str) {
    let DateStr = moment().format('YYYY-M-D h:mm:ss:x')
    let Str = DateStr + "--" + str + "\n"
    // 异步写入数据到文件
    fs.writeFile(file, Str, { encoding: 'utf8', flag: 'a' }, err => {
        if (!err) {
            console.log("写入日志！")
        }
    })
}
function Close () {
    fs.unlink(file, function (error) {
        if (error) {
            console.log(error)
            return false
        }
        console.log('删除日志成功')
    })
}
module.exports = {
    Writetext,
    Close
}